import { Component } from '@angular/core';
import { NavController, NavParams, App } from 'ionic-angular';
import { TabsPage } from '../tabs/tabs';
import { StorageProvider } from '../../providers/storage/storage';
import { HttpserveProvider } from '../../providers/httpserve/httpserve';
import { UrlConstant } from '../../commons/url';

// @IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})
export class LoginPage {
  host: any;
  userName: any;
  passWord: any;
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public app: App,
    private storage: StorageProvider,
    private http: HttpserveProvider,
    private url: UrlConstant,
  ) {

  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad LoginPage');
  }
  login() {
    let parmars = {
      e: this.userName,
      p: this.passWord
    }
    this.http.post(this.url.Login, parmars)
      .subscribe(data => {
        if (data != undefined) {
          this.storage.write('User', data);
          this.app.getRootNav().setRoot(TabsPage);
        }
      }, err => {
        console.log(err);
      });
  }
}
